package com.andy.util;



import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Created on 17/7/7 Biao.wei.
 * 
 */
public class CharactorUtil {

    // 生成bits位随机数或字母
    public static String generateNBitsNumbersOrCharacters(int bits) {
    	char[] symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
    	ThreadLocalRandom rnd = ThreadLocalRandom.current();
	        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < bits; i++)
            sb.append(symbols[rnd.nextInt(symbols.length)]);

        return sb.toString();
    }
    
    //单纯点生成bits位随机数
    public static String generateNBitsNumbers(int bits) {
    	int a = (int) ( 9 * Math.pow(10, bits-1));
    	int b = (int) Math.pow(10, bits-1);
        return (new Random()).nextInt(a) + b + "";
    }

	// 判断一个字符是否是中文
	public static boolean isChinese(char c) {
		return c >= 0x4E00 && c <= 0x9FA5;// 根据字节码判断
	}

	// 判断一个字符串是否含有中文
	public static boolean containsChineseStr(String str) {
		if (str == null) {
			return false;
		}
		for (char c : str.toCharArray()) {
			if (isChinese(c)) {
				return true;
			}
		}
		return false;
	}
}
